package smartcounters.androidclient.model;

import java.util.LinkedList;

import org.ksoap2.serialization.SoapObject;

public class AccountInfo {
	private int m_AccountID;
    private String m_Country;
    private String m_City;
    private String m_Street;
    private int m_House;
    private int m_Apartment;
    private String m_Phone;
    private double m_Longitude;
    private double m_Latitude;
    
    private LinkedList<Integer> m_UsersAssociatedWith;
    
    public AccountInfo(){
    	m_AccountID = 0;
    	m_Apartment = -1;
    	m_UsersAssociatedWith = new LinkedList<Integer>();
    }
    
    public int getAccountID(){
    	return m_AccountID;
    }
    
    public void setAccountID(int i_AccountID){
    	m_AccountID = i_AccountID;
    }
    
    public String getCountry(){
    	return m_Country;
    }
    
    public void setCountry(String i_Country){
    	m_Country = i_Country;
    }
    
    public String getCity(){
    	return m_City;
    }
    
    public void setCity(String i_City){
    	m_City = i_City;
    }
    
    public String getStreet(){
    	return m_Street;
    }
    
    public void setStreet(String i_Street){
    	m_Street = i_Street;
    }
    
    public int getHouse(){
    	return m_House;
    }
    
    public void setHouse(int i_House){
    	m_House = i_House;
    }
    
    public int getApartment(){
    	return m_Apartment;
    }
    
    public void setApartment(int i_Apartment){
    	m_Apartment = i_Apartment;
    }
    
    public String getPhone(){
    	return m_Phone;
    }
    
    public void setPhone(String i_Phone){
    	m_Phone = i_Phone;
    }
    
    public double getLongitude(){
    	return m_Longitude;
    }
    
    public void setLongitude(double i_Longitude){
    	m_Longitude = i_Longitude;
    }
    
    public double getLatitude(){
    	return m_Latitude;
    }
    
    public void setLatitude(double i_Latitude){
    	m_Latitude = i_Latitude;
    }
    
    public LinkedList<Integer> getUsersAssociatedWith(){
    	return m_UsersAssociatedWith;
    }
    
    public void setUsersAssociatedWith(LinkedList<Integer> i_UsersAssociatedWith){
    	m_UsersAssociatedWith = i_UsersAssociatedWith;
    }
    
    public static AccountInfo CreateFromSoapObject(SoapObject accountSoapObject){
    	AccountInfo accountInfo = new AccountInfo();
		accountInfo.setAccountID(Integer.parseInt(accountSoapObject.getProperty("AccountID").toString()));
		accountInfo.setCountry(accountSoapObject.getProperty("Country").toString());
		accountInfo.setCity(accountSoapObject.getProperty("City").toString());
		accountInfo.setStreet(accountSoapObject.getProperty("Street").toString());
		accountInfo.setHouse(Integer.parseInt(accountSoapObject.getProperty("House").toString()));
		if (accountSoapObject.getProperty("Apartment") != null){
			accountInfo.setApartment(Integer.parseInt(accountSoapObject.getProperty("Apartment").toString()));
		}
		accountInfo.setPhone(accountSoapObject.getProperty("Phone").toString());
		accountInfo.setLongitude(Double.parseDouble(accountSoapObject.getProperty("Longitude").toString()));
		accountInfo.setLatitude(Double.parseDouble(accountSoapObject.getProperty("Latitude").toString()));
		
		SoapObject property = (SoapObject)accountSoapObject.getProperty("UsersAssociatedWith");
		LinkedList<Integer> users = new LinkedList<Integer>();
		
		for (int i = 0; i < property.getPropertyCount(); i++){
			users.add(Integer.parseInt(property.getProperty(i).toString()));
		}
		
		accountInfo.setUsersAssociatedWith(users);
		
		return accountInfo;
    }
}
